package com.ilibrary.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.ilibrary.base.MyAjaxAction;
import com.ilibrary.service.CategoryService;
import com.ilibrary.web.dto.ResultDto;
import com.ilibrary.web.vo.CategoryVO;

public class DoQueryCategoryListAction extends MyAjaxAction {
	
	private CategoryService categoryService;
	
	public CategoryService getCategoryService() {
		return categoryService;
	}
	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	@Override
	protected JSONObject doExecute(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
		JSONObject jo = new JSONObject();
		JSONArray ja = new JSONArray();
		JSONObject joo = null;
		ResultDto<CategoryVO> resultDto = categoryService.findAll();
		List<CategoryVO> categoryVOList = resultDto.getResultList();
		for (CategoryVO categoryVO : categoryVOList) {
			joo = new JSONObject();
			joo.put("categoryId", categoryVO.getCategoryId());
			joo.put("categoryName", categoryVO.getCategoryName());
			joo.put("categoryDesc", categoryVO.getCategoryDesc());
			ja.add(joo);
		}
		jo.put("data", ja);
		return jo;
	}

}
